//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Components;
using CommunityServer.Blogs.Controls;
using CommunityServer.Components;
using CommunityServer.ControlPanel.Controls;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Controls;
using ResourceControl = CommunityServer.ControlPanel.Controls.ResourceControl;
using ResourceLinkButton = CommunityServer.ControlPanel.Controls.ResourceLinkButton;
using ResourceManager = CommunityServer.ControlPanel.Components.ResourceManager;

namespace CommunityServer.ControlPanel.Blogs
{
	public class DefaultPostSettings : BaseBlogPage
	{

		#region Child Controls

		protected ResourceLinkButton SaveButton;
		protected ConfigOKStatusMessage Status;
		protected YesNoRadioButtonList ynEnableReplies;
		protected CommentModerationDropDownList ModerationDDL;
		protected FeedbackNotificationDropDownList NotificationType;
		protected YesNoRadioButtonList ynEnableRatings;
		protected YesNoRadioButtonList ynEnableTrackbacks;
		protected YesNoRadioButtonList ynAggregatePost;
		protected YesNoRadioButtonList ynCommunity;
		protected YesNoRadioButtonList ynSyndicateExcerpt;
		protected YesNoRadioButtonList ynEnableCrossPostingDefault;
		protected ControlPanelSelectedNavigation SelectedNavigation1;
		protected HtmlTableRow CrossPostingRow;
		protected YesNoRadioButtonList ynAutoName;
        protected YesNoRadioButtonList ynNotifyAllOwners;

		#endregion

		override protected void OnInit(EventArgs e)
		{
			this.SaveButton.Click += new EventHandler(this.SaveButton_Click);
			this.Load += new EventHandler(this.Page_Load);
			base.OnInit(e);
            this.RefreshCurrentWeblog();
		}


		private void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{

				if (!WeblogConfiguration.Instance().EnableCrossPosting)
					CrossPostingRow.Visible = false;

				ynEnableReplies.SelectedValue = CurrentWeblog.EnableCommentsDefault;
				ynEnableRatings.SelectedValue = CurrentWeblog.EnableRatingsDefault;
				ynEnableTrackbacks.SelectedValue = CurrentWeblog.EnableTrackbacksDefault;
				ynAggregatePost.SelectedValue = CurrentWeblog.EnablePostAggregationDefault;
				ynCommunity.SelectedValue = CurrentWeblog.EnableCommunityParticipationDefault;
				ynSyndicateExcerpt.SelectedValue = CurrentWeblog.SyndicateExcerptDefault;
				ynEnableCrossPostingDefault.SelectedValue = CurrentWeblog.EnableCrossPostingDefault;
				ListItem li = ModerationDDL.Items.FindByValue(CurrentWeblog.ModerationTypeDefault.ToString());
				if (li != null)
					li.Selected = true;

				NotificationType.SelectedValue = CurrentWeblog.FeedbackNotificationType;
				ynAutoName.SelectedValue = CurrentWeblog.AutoNamePosts;
                ynNotifyAllOwners.SelectedValue = CurrentWeblog.EnableAllOwnerNotification;

			}
		}

		private void SaveButton_Click(object sender, EventArgs e)
		{
			if (Page.IsValid)
			{

				CurrentWeblog.EnableCommentsDefault = ynEnableReplies.SelectedValue;
				CurrentWeblog.EnableRatingsDefault = ynEnableRatings.SelectedValue;
				CurrentWeblog.EnableTrackbacksDefault = ynEnableTrackbacks.SelectedValue;
				CurrentWeblog.EnablePostAggregationDefault = ynAggregatePost.SelectedValue;
				CurrentWeblog.EnableCommunityParticipationDefault = ynCommunity.SelectedValue;
				CurrentWeblog.SyndicateExcerptDefault = ynSyndicateExcerpt.SelectedValue;
				CurrentWeblog.EnableCrossPostingDefault = ynEnableCrossPostingDefault.SelectedValue;
				CurrentWeblog.ModerationTypeDefault = (CommentModerationType)Enum.Parse(typeof(CommentModerationType), ModerationDDL.SelectedValue);
				CurrentWeblog.FeedbackNotificationType = NotificationType.SelectedValue;
				CurrentWeblog.AutoNamePosts = ynAutoName.SelectedValue;
                CurrentWeblog.EnableAllOwnerNotification = ynNotifyAllOwners.SelectedValue;

				Weblogs.Update(CurrentWeblog);

				Status.Success = true;
				Status.Visible = true;
			}
		}

	}
}
